<!--#INCLUDE FILE="config.asp"-->
<%
if(Session("CostabajaAccessLevel") <> 2 and Session("CostabajaAccessLevel") <> 3 ) then
	Response.Redirect("default.asp?msg=invalid")
end if

 'Endcrypt information of CC
Set objEncrypter = Server.CreateObject ("Hyeongryeol.StringEncrypter")
objEncrypter.Key = edCode
objEncrypter.InitialVector = conIV
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="../styles.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style>
ul li {
	list-style:none;
	border-bottom: 1px dashed #999999;
    display: block;
    padding: 3px;
}
.linkHistory {padding-right:20px;}
</style>
<!-- DATE PICKER SCRIPT -->
<link type="text/css" href="../css/jquery-ui-1.8.21.custom.css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../js/jquery-ui-1.8.21.custom.min.js"></script>
  <!-- END DATE PICKER SCRIPT -->
  
  <script> 
  $(document).ready(function(){
  $('ul.guest_timeline_list li:nth-child(odd)').addClass('alternate');
});
</script>


<title>Pendiente por Aprovacion :: Costa Baja</title>

</head>
<body>
<%
	if(request("gId") <> "") then
		guestID = request("gId")
	else 
		guestID = 0
	end if
	
	sqlstring = ""
	sqlstring = sqlstring & "SELECT DISTINCT Guests.*, Travels.* , Reservation.Location, Codes.* "
	sqlstring = sqlstring & "FROM Guests "
	sqlstring = sqlstring & "INNER JOIN Guests_Travels on Guests.GuestID = Guests_Travels.GuestID "
	sqlstring = sqlstring & "INNER JOIN Travels on Guests_Travels.TravelID = Travels.TravelID "
	sqlstring = sqlstring & "INNER JOIN Reservation on Reservation.TravelId = Travels.TravelID "
	sqlstring = sqlstring & "INNER JOIN Codes on Travels.CodeID = Codes.CodeID "
	sqlstring = sqlstring & "WHERE Guests.GuestID ="& guestID
	
	set objConnect = server.createObject("ADODB.Connection")   

	objConnect.Open conStr

	set TblTemp = server.createobject("Adodb.Recordset")
	
	TblTemp.Open sqlstring, objConnect
	
	dim count
	
	dim travelsAreals, strItem
	SET travelsAreals = CreateObject("Scripting.Dictionary")
	count = 0
	Do Until TblTemp.EOF
		count = count + 1
			Travelid = TblTemp("TravelID")
			Name = TblTemp("Name")
			Middle = TblTemp("Middle")
			Surname = TblTemp("Surname")
			Email = TblTemp("Email")
			Address1 = TblTemp("Address1")
			City = TblTemp("City")
			Province = TblTemp("Province")
			ZipCode = TblTemp("Zip")
			Country = TblTemp("Country")
			Phone = TblTemp("PhoneNumber")
			
			TotalNumberGuests = TblTemp("TotalNumberGuests")
			NumberChildren = TblTemp("NumberChildren")
			ExtraNight = TblTemp("ExtraNight")
			status = TblTemp("StatusID")
			tamano = TblTemp("RoomSize")
			location = TblTemp("Location")
			producto = TblTemp("ProductID")
			propaid = TblTemp("PropertyID")
			Code = TblTemp("Code")
			
			travelsAreals.Add ""&count, Array(TotalNumberGuests,NumberChildren,ExtraNight,Travelid,status,tamano,location,producto,propaid,Code)	
	TblTemp.MoveNext
	Loop

%>

<script type="text/javascript">
	$(function() {
	var checkClick = false;
	var countClick = 0;
		$('.aprovar').unbind();
		$('.aprovar').click(function() { 
		
			var buttonId = $(this).attr('id');
			var numberTravel = buttonId.substring("AprovarF_".length+1);
			alert(numberTravel);
			var approveId = buttonId.substring("AprovarF_".length-2);
			// AprovarF_
			var temp = buttonId.substring("AprovarF_".length-1);
			// check reservation textbox <> empty
			if ($("#reservation"+approveId).val() == '')
			{
				alert('please input value to reservation');
				$("#reservation"+approveId).focus();
				return false;
			}
			
			if ($("#Location"+numberTravel).val() == "ad")
			{
				alert('please select Location');
				$("#Location"+numberTravel).focus();
				return false;
			}
			
			var remainingNumberButton = 1;
			var numberButton = buttonId.substring(8,9);
			if (numberButton == 1)
				remainingNumberButton = 2; 
			$.ajax({
				type:"GET",
				url: "approve_process.asp",
				dataType: "html",
				data: {
					GuesId: $("#guesId").val(),
					reservationCode:$("#reservation"+approveId).val(), 
					actualArrival:$("#arrival"+approveId).val(),
					actualDeparture:$("#departure"+approveId).val(),
					travelId:$("#travelID"+numberButton+"_"+numberTravel).val(),
					location:$("#Location"+numberTravel).val(),
					habitacion:$("#Habitacion"+numberTravel).val()
				},
				async: false,
				success: function(data){ 
					$("#Aprovar"+approveId).val('Aprovado');
					$("#Aprovar"+approveId).attr("disabled", "true");
					for (var i = 1; i <= <%=count%>; i++) {
						$("tr#F"+remainingNumberButton+"_"+i).css('display','none');
						$("#travelID"+remainingNumberButton+"_"+i).val('');
					}
					$("#travelID"+temp).val('');
					countClick ++;
					// Count click approval
					// Must click approval or denied only one time, not refresh or go out of page 
					// Because that, process will not true
					if (countClick == <%=count%>){
						$("#Deny").css('display','none');
						$("#reason").css('display','none');
						$("#Home").css('display','block');
					}
					
					checkClick = true;
				},
				error: function(){
					alert('error');
				}
			});
			return false;
		
		});
		
		$("#Home").click(function(){
			 $(window.location).attr('href', 'costabaja-dashboard.asp');
		});
		
		$("input[name='reservationOther']").focus(function() {
			if (!checkClick) {
				alert('Please approvar primary reservation detail');
				return false;
			}
		});
		
		$('.linkHistory').unbind();
		$('.linkHistory').click(function(ev) { 
			var buttonId = $(this).attr('id');
			var guestId = $("#guestID").val();
			window.open('HistoryDetail.asp?historyName='+buttonId+'&guestId='+guestId,
			'History Detail','width=800,height=600');
			ev.preventDefault();
			return false;
		});
		
		if ($('#addNewNote'))
		$('#addNewNote').click(function(){
			$.ajax({
				type:"POST",
				url: "add_Notes.asp",
				dataType: "html",
				data: {note:$("#costabajaNote").val(), guestid:$("#guesId").val()},
				async: false,
				success: function(data){ 
					
					$('#success').html('<label>Add note successfully!</label><br />');
				}
			});
			return false;
		});
		
	});
	</script>
<div id="main_wrapper">
    	<div class="main_wrapper_margin">
        	
            <div class="admin_top_menu">
            <!--#INCLUDE FILE="costabaja_menu.asp"--> 
           	</div>
        
    		<h1>Pendiente por Aprovacion: <%=Name &" "&Surname%></h1>
         	<div class="clear"></div>
            
            <hr/>
          <fieldset>
           	<legend>Informacion Personal</legend>
            <table cellpadding="0" width="100%">
            	<input type="hidden" id="guestID" name="guestID" value="<%=guestID%>" />
                <tr> <!-- ROW -->
                	<td width="33%">
            		<label>Nombre: </label><br />
					<input type="text" value="<%=Name%>" name="name" id="name" />
  					</td>
                    <td width="33%">
                    <label>Apellido: </label><br />
					<input type="text" value="<%=Surname%>" name="sName" id="sName" />
                    </td>
                
                	<td width="33%">
            		<label>Telefono: </label><br />
					<input type="text" value="<%=Phone%>" name="phone" id="phone" />
  					</td>
					</tr><!-- END ROW -->
                
                 <tr> <!-- ROW -->
                    <td width="33%">
                    <label>E-mail: </label><br />
					<input type="text" value="<%=Email%>" name="email" id="email"/>
            		</td>
                
                
                    <td>
            	<label>Direccion 1: </label><br />
                <input type="text" value="<%=Address1%>" name="address1" id="address1" />
            		</td>
                    <td>
             <label>Ciudad: </label><br />
                <input type="text" name="Ciudad" id="Ciudad" value="<%=City%>"/>
            		</td>
                 </tr><!-- END ROW -->
                
               <tr> <!-- ROW -->
                    <td>
            	<label>Stado / Provincia: </label><br />
                <input type="text" name="Stado" id="Stado" value="<%=Province%>"/>
            		</td>
                    <td>
            	<label>Codigo Postal: </label><br />
                <input type="text" name="Postal" id="Postal" value="<%=ZipCode%>"/>
            		</td>
                    <td>
             <label>Pais: </label><br />
                <input type="text" name="Pais" id="Pais" value="<%=Country%>"/>
            		</td>
                 </tr><!-- END ROW -->
                    
            </table>
            
           </fieldset>
  
 <form action="denied-process.asp" method="get">

<!-- SECOND PART OF THE FORM -->           
           <fieldset>
           		<legend>Informacion de Viaje </legend>
     
<%
dim number
For Each strItem In travelsAreals
Do
If (travelsAreals(strItem)("4") <> 2) Then Exit Do
number = number + 1

		Dim x
		x = 0
		sqlstring5 = "SELECT * FROM Reservation WHERE TravelId = "&travelsAreals(strItem)("3")& ""
		set TblTemp2 = server.createobject("Adodb.Recordset")
		if (number = 1) then %>
		<table cellpadding="0" width="100%">
		<%end if%>
				<tr>
		<td><label>Confirmation Code: <%=travelsAreals(strItem)("9")%></label><br /></td>
		</tr>
	<tr>
				<td width="33%">
                    <label>Producto :</label><br />
                     	<select name="Producto" id="Producto">
			    		<option value="0">-- Seleccionar --</option>
            			<option value="Residencia" <% if(travelsAreals(strItem)("7")= "1") then%> selected="selected" <% end if%>>Residencia</option>
                		<option value="Full/Ownership" <% if(travelsAreals(strItem)("7")= "2") then%> selected="selected" <% end if%>>Full/Ownership</option>
            			</select>
            		</td>
					<td width="33%">
            	<label>Propiedad: </label><br />
            			<select name="Propiedad" id="Propiedad">
			    		<option value="0">-- Seleccionar --</option>
            			<option value="VM - Vista Mar" <% if(travelsAreals(strItem)("8")= "1") then%> selected="selected" <% end if%>>VM - Vista Mar</option>
                		<option value="LC - Las Colinas Resort" <% if(travelsAreals(strItem)("8")= "2") then%> selected="selected" <% end if%>>LC Las Colinas Resort</option>
            			</select>
  					</td>
					<td width="33%">
                       <label># BR: </label><br />
            			<select name="Habitacion" id="Habitacion<%=number%>" class="roomsize">
			    		<option value="0">-- Seleccionar --</option>
            			<option value="1 BR" <% if(travelsAreals(strItem)("5")= "1 BR") then%> selected="selected" <% end if%>>1 BR</option>
                		<option value="2 BR" <% if(travelsAreals(strItem)("5")= "2 BR") then%> selected="selected" <% end if%>>2 BR</option>
                		<option value="3 BR" <% if(travelsAreals(strItem)("5")= "3 BR") then%> selected="selected" <% end if%>>3 BR</option>
            			</select>
       
            		</td>
                    <td width="33%">
                       <label>Location: </label><br />
            			<select name="Location" id="Location<%=number%>" class="location">
			    		<option value="ad" id="hide">-- Seleccionar --</option>
			    		<option value="LC" <% if(travelsAreals(strItem)("6")= "LC") then%> selected="selected" <% end if%>>LC</option>
            			<option value="VM" <% if(travelsAreals(strItem)("6")= "VM") then%> selected="selected" <% end if%>>VM</option>
                		<option value="H" <% if(travelsAreals(strItem)("6")= "H") then%> selected="selected" <% end if%>>H</option>
            			</select>
       
            		</td>
                    
                    <td>&nbsp;
                    
                    </td>
                    
                </tr><!-- END ROW -->	
		<%
		TblTemp2.Open sqlstring5, objConnect
		Do Until TblTemp2.EOF
		x = x + 1
		
			ActualArrival = TblTemp2("ActualArrival")
			ActualDeparture = TblTemp2("ActualDeparture")
		
	%>       
                 <tr id="F<%=x%>_<%=number%>"> <!-- ROW -->
					<input type="hidden" id="travelID<%=x%>_<%=number%>" name="travelID<%=x%>_<%=number%>" value="<%=travelsAreals(strItem)("3")%>" />
                	<td width="33%">
            		<label>Fecha <%=x%></label>
  					</td>
                    <td width="33%">
                    <label>Llegada: </label><br />
                    <input type="text" id="arrivalF<%=x%>_<%=number%>" value="<%=ActualArrival%>" />
            		</td>
                    <td width="33%">
                    <label>Salida: </label><br />
					<input type="text" id="departureF<%=x%>_<%=number%>" value="<%=ActualDeparture%>" />
                    </td>
					<td width="33%">
                    <label>Reservation Code: </label><br />
					<%if (number = 1) then%>
					<input type="text" value="" id="reservationF<%=x%>_<%=number%>" name="reservationPrimary"/>
                    <%else %>
					<input type="text" value="" id="reservationF<%=x%>_<%=number%>" name="reservationOther"/>
					<%end if%>
					</td>
                    <td align="left" valign="middle">
                   <input type="button" class="aprovar" value="Aprovar" id="AprovarF<%=x%>_<%=number%>" />
                    </td>
                </tr><!-- END ROW -->
                    
    <%
			TblTemp2.MoveNext
			Loop
		%>  
            
                <tr> <!-- ROW -->
                	<td width="33%">
            		<label>Numero Total de Invitados: </label><br />
                    <select>
                    <%For i = 0 To 5 %>
                    <option value="<%=i%>" <% if(travelsAreals(strItem)("0")= i) then%> selected="selected" <% end if%>><%=i%></option>
					<%Next%>                  
                    </select>
  					</td>
                    <td width="33%">
                    <label>Numero de Niños: </label><br />
                    <select>
                     <%For i = 0 To 10 %>
                    <option value="<%=i%>" <% if(travelsAreals(strItem)("1") = i) then%> selected="selected" <% end if%>><%=i%></option>
					<%Next%>                  
                    </select>
                    </td>
                    <td width="33%">
                    <label>Noches Extras: </label><br />
					<select>
                    <%For i = 0 To 5 %>
                    <option value="<%=i%>" <% if(travelsAreals(strItem)("2")= i) then%> selected="selected" <% end if%>><%=i%></option>
					<%Next%> 
                    </select>
                    </td>
					</tr>
				<tr><td colspan="4"><hr></td></tr>
          <%
		  Loop While False
	Next%>
	<input type="hidden" id="guesId" name="guesId" value="<%=guestID%>" />
	<input type="hidden" id="countTravel" name="countTravel" value="<%=travelsAreals.Count%>" />	
	<tr> <!-- ROW -->
                	<td width="33%" colspan="3">
                    <label>Costabaja add note to guest: </label>
					<input type="text" name="note" value="" id="costabajaNote"/>
                    <input type="button" id="addNewNote" value="Add new note"/>
            		</td>
					<td id="success"></td>
                 
                </tr><!-- END ROW -->
          </table>
<%
IF (number <> 0) then%>     
<table>          
			   <tr> <!-- ROW -->
                	<td width="33%">
                    <label>Razón negar: </label><br />
					<input type="text" name="reason" id="reason" value="" />
                    </td>
                    <td valign="bottom" align="center" colspan="2">
                    <br />
                    <input type="submit" id="Deny" value="Negar"/>
					<input type="button" id="Home"  value="Go Dashboard" style="display:none;"/>
            		</td>
                 
                </tr><!-- END ROW -->
				 </table>
 <%else%>
<div>
No Travel To approve
</div> 
<%end if%>
           
		                
           </fieldset><!-- END OF FADED -->
     
           </form>
           <fieldset>
		   <legend>Historia de Huesped</legend>
            <ul class="guest_timeline_list">
<%
		sqlstring4 = "SELECT  * FROM ( SELECT  DISTINCT Name FROM Historys ) mto JOIN Historys mt ON  mt.HistoryID = (SELECT  TOP 1 HistoryID FROM  Historys mti WHERE mti.Name = mto.Name AND GuestID ="&guestID&") ORDER BY Date DESC "
		set objConnect4 = server.createObject("ADODB.Connection")   

		objConnect4.Open conStr

		set TblTemp4 = server.createobject("Adodb.Recordset")
			
			TblTemp4.Open sqlstring4, objConnect4
			
		Do Until TblTemp4.EOF
			
			idHistory = TblTemp4("HistoryID")
			DateOfHistory = TblTemp4("Date")
			NameOfHistory = TblTemp4("Name")
			IsNote = TblTemp4("IsNote")
			If (IsNote = true) then
				IsNote = 1
			else 
				IsNote = 0
			end if
	%>
			<%if (IsNull(DateOfHistory) = False) then%>
				<%if (NameOfHistory = "Sent Email") THEN%>	
					<li><a href="#" id="historySentEmail"><%=NameOfHistory%></a> <span><%=FormatDateTime(DateOfHistory,2)%></span></li>
				<%else%>
					<li><a href="#" id="<%=idHistory&"_"&IsNote%>" class="linkHistory"><%=NameOfHistory%></a> <span><%=FormatDateTime(DateOfHistory,2)%></span></li>
				<%end if%>
			<%end if%>
     <%
	TblTemp4.MoveNext
	Loop

%>                                 
            </ul>

		   </fieldset>
        
    	</div><!-- END .main_wrapper_margin -->
	</div><!-- END #main_wrapper -->

         <!-- FOOTER -->
         
         <!--#INCLUDE FILE="costabaja_footer.asp"-->
         
         <!-- END FOOTER -->   

</body>
</html>
